import { Toast } from 'antd-mobile'
import { createAction, NavigationActions } from '../../utils/index'
import * as homeService from '../../services/home'
import * as commonService from '../../services/common'
import * as Libs from '../../utils/Libs'

export default {
  namespace: 'home',
  state: {
    mainTime: {
      startTime: Libs.getFirstMonth(),
      endTime: Libs.getCurrentMonth(),
      timeType: 'year'
    },
    detailMsg: []
  },
  reducers: {
    changeTime(state, { payload }) {
      return { ...state, ...payload}
    },
    initDetail(state, {payload}) {
      return {...state, detailMsg: []}
    },
    changeState(state, {payload}) {
      return {...state, ...payload}
    }
  },
  effects: {
    *getA({ payload }, { call, select, put}) {
      const callback = payload.callback
      console.log('home get A')
      const xx  = yield call(homeService.getChouData, {})
      console.log('home get A end')
      callback()

    },
    *getB({payload}, { call, select, put}) {
      console.log('home get B')
      const xx = yield call(homeService.getChouData, {})
      console.log('home get B end')
    },
    *getCommonDetail({payload}, {call, select, put}) {
      const params = {}
      params.startTime = (payload.startTime || "").replace('.','-')
      params.endTime = (payload.endTime || "").replace('.','-')
      params.useArea = payload.useArea
      const resp = yield call(commonService.getCommonLineMoney, params)
      if (resp.resultCode !== 200) {
        Toast.info(resp.msg, 1)
        return false
      }
      // const analyseDetail = yield call(commonService.analyzeDetail, resp.data)

      yield put(createAction("changeState")({
        detailMsg: resp.data
      }))
    }
  },
  subscriptions: {
  },
}
